#include "feInterpolation.h"

//---------------------------------------------------------------------------------------------------------------------------------
inline double feInterpolation::QuadBasis1(double iX1, double iX2, double iX3, double iX)
{
	return (iX - iX2)*(iX - iX3)/((iX1 - iX2)*(iX1 - iX3));
}


//---------------------------------------------------------------------------------------------------------------------------------
inline double feInterpolation::QuadBasis2(double iX1, double iX2, double iX3, double iX)
{
	return (iX - iX1)*(iX - iX3)/((iX2 - iX1)*(iX2 - iX3));
}


//---------------------------------------------------------------------------------------------------------------------------------
inline double feInterpolation::QuadBasis3(double iX1, double iX2, double iX3, double iX)
{
	return (iX - iX1)*(iX - iX2)/((iX3 - iX2)*(iX3 - iX1));
}


//----------------------------------------------------------------------------------------------------------------------------------
double feInterpolation::Quadratic(double iXs[3], double iFs[3], double iX)
{
	return	QuadBasis1(iXs[0], iXs[1], iXs[2], iX)*iFs[0] +
			QuadBasis2(iXs[0], iXs[1], iXs[2], iX)*iFs[1] +
			QuadBasis3(iXs[0], iXs[1], iXs[2], iX)*iFs[2];
}


//----------------------------------------------------------------------------------------------------------------------------------
inline double feInterpolation::LinearBasis1(double iX1, double iX2, double iX)
{
	return (iX-iX2)/(iX1-iX2);
}


//----------------------------------------------------------------------------------------------------------------------------------
inline double feInterpolation::LinearBasis2(double iX1, double iX2, double iX)
{
	return (iX-iX1)/(iX2-iX1);
}


//----------------------------------------------------------------------------------------------------------------------------------
double feInterpolation::Linear(double iXs[2], double iFs[2], double iX)
{
	return  LinearBasis1(iXs[0], iXs[1], iX)*iFs[0] +
			LinearBasis2(iXs[0], iXs[1], iX)*iFs[1];
}


//---------------------------------------------------------------------------------------------------------------------------------
double feInterpolation::LinDeriv(double iXs[2], double iFs[2], double iX)
{
	return (iFs[1] - iFs[0])/(iXs[1]-iXs[0]);
}


//---------------------------------------------------------------------------------------------------------------------------------
inline double feInterpolation::QuadBasisDeriv1(double iX1, double iX2, double iX3, double iX)
{	
	return ((iX - iX2)+(iX - iX3))/((iX1 - iX2)*(iX1 - iX3));
}


//---------------------------------------------------------------------------------------------------------------------------------
inline double feInterpolation::QuadBasisDeriv2(double iX1, double iX2, double iX3, double iX)
{
	return ((iX - iX1)+(iX - iX3))/((iX2 - iX1)*(iX2 - iX3));
}


//---------------------------------------------------------------------------------------------------------------------------------
inline double feInterpolation::QuadBasisDeriv3(double iX1, double iX2, double iX3, double iX)
{
	return ((iX - iX1)+(iX - iX2))/((iX3 - iX1)*(iX3 - iX2));
}


//----------------------------------------------------------------------------------------------------------------------------------
double feInterpolation::QuadDeriv(double iXs[3], double iFs[3], double iX)
{
	return	QuadBasisDeriv1(iXs[0], iXs[1], iXs[2], iX)*iFs[0] +
			QuadBasisDeriv2(iXs[0], iXs[1], iXs[2], iX)*iFs[1] +
			QuadBasisDeriv3(iXs[0], iXs[1], iXs[2], iX)*iFs[2];			
}